package java44th.group.controller.admin.footprint;

import java44th.group.bean.common.BasePageInfo;
import java44th.group.bean.common.CommonData;
import java44th.group.bean.po.MarketFootprint;
import java44th.group.bean.admin.vo.BaseRespVo;
import java44th.group.service.admin.footprint.FootprintService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ProjectName project-second
 * @Descriptiom TODO
 * @Aurhor: 蔡文强
 * @Since: 2022/10/12 20:34
 */
@RestController
@RequestMapping("admin/footprint")
public class FootpringController {

    @Autowired
    FootprintService footprintService;

    // http://182.92.235.201:8083/admin/footprint/list?page=1&limit=20&userId=1&goodsId=1&sort=add_time&order=desc
    @RequiresPermissions("*")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public BaseRespVo list(BasePageInfo basePageInfo, String userId, String goodsId) {

        Integer integerUserId = null;
        if (userId != null) {
            try {
                integerUserId = Integer.parseInt(userId);
            } catch (Exception e) {
                return BaseRespVo.error(400, "请输入正确的id值");
            }
        }
        Integer integerGoodsId = null;
        if (goodsId != null) {
            try {
                integerGoodsId = Integer.parseInt(goodsId);
            } catch (Exception e) {
                return BaseRespVo.error(400, "请输入正确的id值");
            }
        }

        CommonData<MarketFootprint> marketFootprintCommonData = footprintService.list(basePageInfo, integerUserId,
                integerGoodsId);

        return BaseRespVo.ok(marketFootprintCommonData);
    }

}
